<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>student_update</title>
		<link rel="shortcut icon" href="../../images/my/favicon.ico" />
		<link rel="bookmark" href="../../images/my/favicon.ico" />
		<link rel="stylesheet" href="../../statics/layui/css/layui.css" />
		<link rel="stylesheet" href="../../css/admin/common.css" />
		<link rel="stylesheet" href="../../css/admin/update_my_base_info.css" />
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row">
				<div class="layui-col-md12">
					<div class="layui-card layui-anim layui-anim-upbit">
						<div class="layui-card-header">修改学生信息
							<span class="btn_right">
								<button type="button" id="back" title="返回" class="layui-btn layui-btn-normal layui-btn-xs" onclick="javascript:window.history.back(-1);"><i class="layui-icon">&#xe65c;</i>返回上一页</button>
								<button type="button" id="refresh" title="刷新" class="layui-btn layui-btn-normal layui-btn-xs"><i class="layui-icon layui-icon-refresh"></i></button>
							</span>
						</div>
						<div class="layui-card-body">
							<form class="layui-form" action="">
								<div class="layui-form-item layui-row" id="sId" hidden="hidden">
									<label class="my_layui-form-label layui-col-md1 layui-col-sm1 layui-col-xs12">学生编号：</label>
									<div class="layui-col-md10 layui-col-sm10 layui-col-xs12">
										<input type="text" name="sId" required lay-verify="required|username" autocomplete="off" placeholder="请输入编号" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item layui-row">
									<label class="my_layui-form-label layui-col-md1 layui-col-sm1 layui-col-xs12">学生学号：</label>
									<div class="layui-col-md10 layui-col-sm10 layui-col-xs12">
										<input type="text" name="sNo" required lay-verify="required|username" autocomplete="off" placeholder="请输入学号" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item layui-row">
									<label class="my_layui-form-label layui-col-md1 layui-col-sm1 layui-col-xs12">学生姓名：</label>
									<div class="layui-col-md10 layui-col-sm10 layui-col-xs12">
										<input type="text" name="sName" required lay-verify="required|username" autocomplete="off" placeholder="请输入姓名" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item layui-row">
									<label class="my_layui-form-label layui-col-md1 layui-col-sm1 layui-col-xs12">修改密码：</label>
									<div class="layui-col-md10 layui-col-sm10 layui-col-xs12">
										<input type="password" name="sPass" id="password" required lay-verify="required|username" autocomplete="off" placeholder="请输入密码" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item layui-row">
									<label class="my_layui-form-label layui-col-md1 layui-col-sm1 layui-col-xs12">确认密码：</label>
									<div class="layui-col-md10 layui-col-sm10 layui-col-xs12">
										<input type="password" name="sPass" id="repassword" required lay-verify="required|username" autocomplete="off" placeholder="请确认密码" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item layui-row">
									<label class="my_layui-form-label layui-col-md1 layui-col-sm1 layui-col-xs12">班级：</label>
									<div class="layui-col-md10 layui-col-sm10 layui-col-xs12">
                                        <select name="classId" id="class_num">
											
										</select>
									</div>
								</div>
								<div class="layui-form-item layui-row">
									<label class="my_layui-form-label layui-col-md1 layui-col-sm1 layui-col-xs12" >性别：</label>
									<div class="layui-col-md10 layui-col-sm10 layui-col-xs12" id="sSex">
										<input type="radio" value="1" name="sSex" id="sSex1" style="vertical-align:middle" checked="checked"/>
										<span style="margin-left: -20px;margin-right: 20px;vertical-align:middle;">男</span>
									    <input type="radio" value="0" name="sSex" id="sSex2" />
									    <span style="margin-left: -20px;">女</span>
									</div>
								</div>
								<div class="layui-form-item layui-row">
									<label class="my_layui-form-label layui-col-md1 layui-col-sm1 layui-col-xs12" >学生类型：</label>
									    <div class="layui-col-md10 layui-col-sm10 layui-col-xs12" id="sType">
									    <input type="radio" value="1" name="sType" id="sType1" style="vertical-align:middle" checked="checked"/>
									    <span style="margin-left: -20px;margin-right: 20px;vertical-align:middle;">在校</span>
									    <input type="radio" value="2" name="sType" id="sType2" />
									    <span style="margin-left: -20px;">退学</span>
									    <input type="radio" value="3" name="sType" id="sType3" />
									    <span style="margin-left: -20px;">休学</span>
									</div>
								</div>
								<div class="layui-form-item layui-row">
									<label class="my_layui-form-label layui-col-md1 layui-col-sm1 layui-col-xs1 layui-hide-xs">&nbsp;</label>
									<button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo"></i><span>确认修改</span></button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="../../statics/layui/layui.js"></script>
		<script type="text/javascript" src="../../statics/lay/system/admin/public.js" ></script>
		<script>
			layui.use(['layer', 'form'], function() {
				var layer = layui.layer,
					$ = layui.$,
					form = layui.form,
				laydate = layui.laydate;
				var sId = getUrlParam("sId")
				initData(sId);
				
				//表单监听提交
				form.on('submit(formDemo)', function(data) {
					var user_data = data.field;
					
					var password = document.getElementById("password").value;
                    var repassword = document.getElementById("repassword").value;
                    if(password != repassword){
                        alert("两次密码不一致，请重新输入");
                        return false;
                    }
					user_data=JSON.stringify(user_data)
					$.ajax({
						url: IP + '/api/teacher_eav/sysStudent',
						type: 'PUT',
						data: user_data,
						success: function(result, status, xhr) {
							layer.closeAll('loading');
							layer.msg(result.message, {
								icon: 1,
								time: 1000
							},function(){
								window.location='student-list.html'
							});
						}
					});
					return false;
				});
				form.verify({
					cName: function(value, item) { //value：表单的值、item：表单的DOM对象
						if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
							return '学生学号不能有特殊字符';
						}
						if(!(/^[\S]{1,24}$/.test(value))) {
							return '学生学号必须1到24位，且不能出现空格';
						}
						if(/(^\_)|(\__)|(\_+$)/.test(value)) {
							return '学生学号首尾不能出现下划线\'_\'';
						}
					}
				});
				//初始化页面数据
				function initData(sId) {
					//班级
					showClassOption("class_num");
					form.render('select');
					
					showUser(sId);
				}
				function showUser(sId) {
					$.ajax({
						url: IP + '/api/teacher_eav/sysStudent/'+sId,
						type: 'GET',
						success: function(result, status, xhr) {
							layer.closeAll('loading');	
							$("input[name='sId']").val(result.data.sId);
							$("input[name='sNo']").val(result.data.sNo);
							$("input[name='sName']").val(result.data.sName);
							if(result.data.sSex=="1"){
								$("#sSex1").attr("checked","checked");
							}
							if(result.data.sSex=="0"){
								$("#sSex2").attr("checked","checked");
							}
							if(result.data.sType=="1"){
								$("#sType1").attr("checked","checked");
							}
							if(result.data.sType=="2"){
								$("#sType2").attr("checked","checked");
							}
							if(result.data.sType=="3"){
								$("#sType3").attr("checked","checked");
							}

							$("option[value='"+result.data.classId+"']").prop("selected","selected")
							/*$.each(result.data.roles, function(idx,obj) {
								$("input[type='checkbox'][data-id='"+obj.cId+"']").attr("checked","checked")
							});*/
							
							form.render();
						}
					});
				}
				
			});
		</script>
	</body>

</html>